/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package proj2;

import java.math.BigDecimal;

/**
 * main platform
 * @author Yerong
 */
public class Platform extends javax.swing.JFrame {

    /**
     * Creates new form platform
     */
    // inputerror is the error message for input
    public Errorform inputerror;
    public Errorselect select;
    public About abt;
    public Platform() {
        initComponents();        
        inputerror = new Errorform(this, true);
        select = new Errorselect(this, true);
        abt = new About(this, true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        menuGroup = new javax.swing.ButtonGroup();
        ControljPanel = new javax.swing.JPanel();
        CalculatejButton = new javax.swing.JButton();
        ClearjButton = new javax.swing.JButton();
        PrintjButton = new javax.swing.JButton();
        ExitjButton = new javax.swing.JButton();
        optionjPanel = new javax.swing.JPanel();
        PIjRadioButton = new javax.swing.JRadioButton();
        EjRadioButton = new javax.swing.JRadioButton();
        titleJLabel = new javax.swing.JLabel();
        resultjPanel1 = new javax.swing.JPanel();
        ErrorjLabel1 = new javax.swing.JLabel();
        ExecutionjLabel1 = new javax.swing.JLabel();
        valErrorjLabel1 = new javax.swing.JLabel();
        valExecutionjLabel1 = new javax.swing.JLabel();
        rsltjLabel1 = new javax.swing.JLabel();
        methodjLabel1 = new javax.swing.JLabel();
        resultjPanel2 = new javax.swing.JPanel();
        ErrorjLabel2 = new javax.swing.JLabel();
        ExecutionjLabel2 = new javax.swing.JLabel();
        valErrorjLabel2 = new javax.swing.JLabel();
        valExecutionjLabel2 = new javax.swing.JLabel();
        rsltjLabel2 = new javax.swing.JLabel();
        methodjLabel2 = new javax.swing.JLabel();
        inputjPanel = new javax.swing.JPanel();
        inputjLabel = new javax.swing.JLabel();
        inputjTextField = new javax.swing.JTextField();
        jMenuBar = new javax.swing.JMenuBar();
        FilejMenu = new javax.swing.JMenu();
        clearjMenuItem = new javax.swing.JMenuItem();
        printjMenuItem = new javax.swing.JMenuItem();
        quitjMenuItem = new javax.swing.JMenuItem();
        appjMenu = new javax.swing.JMenu();
        PIjRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem();
        EjRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem();
        HelpjMenu = new javax.swing.JMenu();
        AboutjMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setSize(new java.awt.Dimension(100, 100));

        ControljPanel.setLayout(new java.awt.GridLayout(1, 4));

        CalculatejButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        CalculatejButton.setMnemonic('C');
        CalculatejButton.setText("Calculate");
        CalculatejButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CalculatejButtonActionPerformed(evt);
            }
        });
        ControljPanel.add(CalculatejButton);

        ClearjButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ClearjButton.setMnemonic('l');
        ClearjButton.setText("Clear");
        ClearjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearjButtonActionPerformed(evt);
            }
        });
        ControljPanel.add(ClearjButton);

        PrintjButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        PrintjButton.setMnemonic('P');
        PrintjButton.setText("Print");
        PrintjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PrintjButtonActionPerformed(evt);
            }
        });
        ControljPanel.add(PrintjButton);

        ExitjButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ExitjButton.setMnemonic('E');
        ExitjButton.setText("Exit");
        ExitjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitjButtonActionPerformed(evt);
            }
        });
        ControljPanel.add(ExitjButton);

        buttonGroup.add(PIjRadioButton);
        PIjRadioButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        PIjRadioButton.setText("PI");
        PIjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PIjRadioButtonActionPerformed(evt);
            }
        });

        buttonGroup.add(EjRadioButton);
        EjRadioButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        EjRadioButton.setText("E");
        EjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EjRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionjPanelLayout = new javax.swing.GroupLayout(optionjPanel);
        optionjPanel.setLayout(optionjPanelLayout);
        optionjPanelLayout.setHorizontalGroup(
            optionjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionjPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PIjRadioButton)
                    .addComponent(EjRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        optionjPanelLayout.setVerticalGroup(
            optionjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionjPanelLayout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addComponent(PIjRadioButton)
                .addGap(6, 6, 6)
                .addComponent(EjRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        titleJLabel.setBackground(new java.awt.Color(255, 255, 0));
        titleJLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        titleJLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Bunny.png"))); // NOI18N
        titleJLabel.setText("Approximation of PI and E");

        ErrorjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ErrorjLabel1.setText("Time of Execution:(in milliseconds):");

        ExecutionjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ExecutionjLabel1.setText("Relative Error in Approximation:");

        valErrorjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        valErrorjLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        valExecutionjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        valExecutionjLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        rsltjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rsltjLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        methodjLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        methodjLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        methodjLabel1.setText("Default method");

        javax.swing.GroupLayout resultjPanel1Layout = new javax.swing.GroupLayout(resultjPanel1);
        resultjPanel1.setLayout(resultjPanel1Layout);
        resultjPanel1Layout.setHorizontalGroup(
            resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultjPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ErrorjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(valExecutionjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39))
            .addGroup(resultjPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(resultjPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(ExecutionjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(valErrorjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultjPanel1Layout.createSequentialGroup()
                        .addComponent(methodjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(rsltjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        resultjPanel1Layout.setVerticalGroup(
            resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultjPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rsltjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(methodjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ExecutionjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(valErrorjLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(resultjPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(valExecutionjLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ErrorjLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        ErrorjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ErrorjLabel2.setText("Time of Execution:(in milliseconds):");

        ExecutionjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ExecutionjLabel2.setText("Relative Error in Approximation:");

        valErrorjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        valErrorjLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        valExecutionjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        valExecutionjLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        rsltjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rsltjLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        methodjLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        methodjLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        methodjLabel2.setText("Second method(See About)");

        javax.swing.GroupLayout resultjPanel2Layout = new javax.swing.GroupLayout(resultjPanel2);
        resultjPanel2.setLayout(resultjPanel2Layout);
        resultjPanel2Layout.setHorizontalGroup(
            resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultjPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(resultjPanel2Layout.createSequentialGroup()
                        .addComponent(methodjLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rsltjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultjPanel2Layout.createSequentialGroup()
                        .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(resultjPanel2Layout.createSequentialGroup()
                                .addComponent(ExecutionjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, resultjPanel2Layout.createSequentialGroup()
                                .addComponent(ErrorjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(valErrorjLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                            .addComponent(valExecutionjLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(31, 31, 31))))
        );
        resultjPanel2Layout.setVerticalGroup(
            resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultjPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(methodjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rsltjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ExecutionjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(valErrorjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(resultjPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(valExecutionjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ErrorjLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        inputjLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        inputjLabel.setText("Number of Terms ih Series:");

        inputjTextField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout inputjPanelLayout = new javax.swing.GroupLayout(inputjPanel);
        inputjPanel.setLayout(inputjPanelLayout);
        inputjPanelLayout.setHorizontalGroup(
            inputjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputjPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(inputjLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(inputjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        inputjPanelLayout.setVerticalGroup(
            inputjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, inputjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(inputjLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                .addComponent(inputjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        FilejMenu.setText("File");

        clearjMenuItem.setMnemonic('l');
        clearjMenuItem.setText("Clear");
        clearjMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearjMenuItemActionPerformed(evt);
            }
        });
        FilejMenu.add(clearjMenuItem);

        printjMenuItem.setMnemonic('P');
        printjMenuItem.setText("Print");
        printjMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printjMenuItemActionPerformed(evt);
            }
        });
        FilejMenu.add(printjMenuItem);

        quitjMenuItem.setMnemonic('Q');
        quitjMenuItem.setText("Quit");
        quitjMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitjMenuItemActionPerformed(evt);
            }
        });
        FilejMenu.add(quitjMenuItem);

        jMenuBar.add(FilejMenu);

        appjMenu.setText("Approximation");

        menuGroup.add(PIjRadioButtonMenuItem);
        PIjRadioButtonMenuItem.setText("PI");
        PIjRadioButtonMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PIjRadioButtonMenuItemActionPerformed(evt);
            }
        });
        appjMenu.add(PIjRadioButtonMenuItem);

        menuGroup.add(EjRadioButtonMenuItem);
        EjRadioButtonMenuItem.setText("E");
        EjRadioButtonMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EjRadioButtonMenuItemActionPerformed(evt);
            }
        });
        appjMenu.add(EjRadioButtonMenuItem);

        jMenuBar.add(appjMenu);

        HelpjMenu.setText("Help");

        AboutjMenuItem.setText("About");
        AboutjMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutjMenuItemActionPerformed(evt);
            }
        });
        HelpjMenu.add(AboutjMenuItem);

        jMenuBar.add(HelpjMenu);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(ControljPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(65, 65, 65)
                                .addComponent(titleJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(inputjPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(optionjPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(resultjPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(resultjPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(titleJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inputjPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(optionjPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resultjPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(resultjPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addComponent(ControljPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
 * Exit button can quit the program
 * @author Yerong
 * @param evt 
 */
    private void ExitjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitjButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_ExitjButtonActionPerformed

    private void PIjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PIjRadioButtonActionPerformed
        // synchronization
        menuGroup.clearSelection();
        PIjRadioButtonMenuItem.setSelected(true);
    }//GEN-LAST:event_PIjRadioButtonActionPerformed

    private void CalculatejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalculatejButtonActionPerformed
        //result stores the result        
        BigDecimal result = BigDecimal.ZERO, relative = BigDecimal.ZERO;
        // number if terms
        int number = 0;
        // time
        long startTime =0;
        long endTime =0 ;
        long duration =0;
        if (inputjTextField.getText().length()<1)
        {
            inputerror.setVisible(true);
            return;
        }
        number = Integer.parseInt(inputjTextField.getText());
        System.out.println(""+number);
        if ( number < 2 || number > 2147483647 )
            {
                inputerror.setVisible(true);
                return;
            }
        
        if (PIjRadioButton.isSelected())
        {
            //default method
            PI1 p1 = new PI1();            
            startTime = System.nanoTime();
            result = p1.calculate(number);
            endTime = System.nanoTime();
            duration = (endTime - startTime);
            System.out.println("DEBUG");
            relative = result.subtract(new BigDecimal(Math.PI));
            relative = relative.divide(new BigDecimal(Math.PI),100, BigDecimal.ROUND_HALF_UP);
            rsltjLabel1.setText(""+result.setScale(9, BigDecimal.ROUND_HALF_UP));
                    
            relative = relative.scaleByPowerOfTen(2);
            valExecutionjLabel1.setText(Long.toString(duration));
            valErrorjLabel1.setText(relative.setScale(4, BigDecimal.ROUND_HALF_UP)+"%");
            
            // second method
            PI2 p2 = new PI2();               
            startTime = System.nanoTime();
            result = p2.calculate(number);
            endTime = System.nanoTime();
            //rsltjLabel1.setText("");
            duration = (endTime - startTime);
            System.out.println("DEBUG");
            relative = result.subtract(new BigDecimal(Math.PI));
            relative = relative.divide(new BigDecimal(Math.PI),100, BigDecimal.ROUND_HALF_UP);
            rsltjLabel2.setText(""+result.setScale(9, BigDecimal.ROUND_HALF_UP));
            
            relative = relative.scaleByPowerOfTen(2);
            valExecutionjLabel2.setText(Long.toString(duration));
            valErrorjLabel2.setText(relative.setScale(4, BigDecimal.ROUND_HALF_UP)+"%");
  
        }
        else if (EjRadioButton.isSelected())
        {
            //default method
            E1 eVal = new E1();            
            startTime = System.nanoTime();
            result = eVal.calculate(number);
            endTime = System.nanoTime();
            //rsltjLabel1.setText("");
            duration = (endTime - startTime);
            System.out.println("DEBUG");
            relative = result.subtract(new BigDecimal(Math.E));
            relative = relative.divide(new BigDecimal(Math.E),100, BigDecimal.ROUND_HALF_UP);
            rsltjLabel1.setText(""+result.setScale(9, BigDecimal.ROUND_HALF_UP));
                    
            relative = relative.scaleByPowerOfTen(2);
            valExecutionjLabel1.setText(Long.toString(duration));
            valErrorjLabel1.setText(relative.setScale(4, BigDecimal.ROUND_HALF_UP)+"%");
            
            // Bell method
            E2 eVal2 = new E2();            
            startTime = System.nanoTime();
            result = eVal2.calculate(number);
            endTime = System.nanoTime();
            //rsltjLabel1.setText("");
            duration = (endTime - startTime);
            System.out.println("DEBUG");
            relative = result.subtract(new BigDecimal(Math.E));
            relative = relative.divide(new BigDecimal(Math.E),100, BigDecimal.ROUND_HALF_UP);
            rsltjLabel2.setText(""+result.setScale(9, BigDecimal.ROUND_HALF_UP));
            
            relative = relative.scaleByPowerOfTen(2);
            valExecutionjLabel2.setText(Long.toString(duration));
            valErrorjLabel2.setText(relative.setScale(4, BigDecimal.ROUND_HALF_UP)+"%");

        }
        else
        {
            select.setVisible(true);
            return;
        }        
    }//GEN-LAST:event_CalculatejButtonActionPerformed
/**
 * clear button clears text in results and input
 * @author Yerong
 * @param evt 
 */
    private void ClearjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearjButtonActionPerformed
        // clear input
        inputjTextField.setText("");
        // clear output
        rsltjLabel1.setText("");
        rsltjLabel2.setText("");
        valErrorjLabel1.setText("");
        valErrorjLabel2.setText("");
        valExecutionjLabel1.setText("");
        valExecutionjLabel2.setText("");
    }//GEN-LAST:event_ClearjButtonActionPerformed

    private void quitjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitjMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_quitjMenuItemActionPerformed
    
    // Do the printing
    private void printjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printjMenuItemActionPerformed
        PrintUtilities.printComponent(this);
    }//GEN-LAST:event_printjMenuItemActionPerformed
/**
 * clear button clears text in results and input
 * @author Yerong
 * @param evt 
 */
    private void clearjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearjMenuItemActionPerformed
        // clear input
        inputjTextField.setText("");
        // clear output
        rsltjLabel1.setText("");
        rsltjLabel2.setText("");
        valErrorjLabel1.setText("");
        valErrorjLabel2.setText("");
        valExecutionjLabel1.setText("");
        valExecutionjLabel2.setText("");    
    }//GEN-LAST:event_clearjMenuItemActionPerformed

    private void EjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EjRadioButtonActionPerformed
        // synchronization
        menuGroup.clearSelection();
        EjRadioButtonMenuItem.setSelected(true);
    }//GEN-LAST:event_EjRadioButtonActionPerformed

    private void PIjRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PIjRadioButtonMenuItemActionPerformed
        // synchronization
        buttonGroup.clearSelection();
        PIjRadioButton.setSelected(true);
    }//GEN-LAST:event_PIjRadioButtonMenuItemActionPerformed

    private void EjRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EjRadioButtonMenuItemActionPerformed
        // synchronization 
        buttonGroup.clearSelection();
        EjRadioButton.setSelected(true);
    }//GEN-LAST:event_EjRadioButtonMenuItemActionPerformed
// printing
    private void PrintjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PrintjButtonActionPerformed
        PrintUtilities.printComponent(this);
    }//GEN-LAST:event_PrintjButtonActionPerformed

    private void AboutjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutjMenuItemActionPerformed
        abt.setVisible(true);
    }//GEN-LAST:event_AboutjMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(platform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(platform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(platform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(platform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Platform().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem AboutjMenuItem;
    private javax.swing.JButton CalculatejButton;
    private javax.swing.JButton ClearjButton;
    private javax.swing.JPanel ControljPanel;
    private javax.swing.JRadioButton EjRadioButton;
    private javax.swing.JRadioButtonMenuItem EjRadioButtonMenuItem;
    private javax.swing.JLabel ErrorjLabel1;
    private javax.swing.JLabel ErrorjLabel2;
    private javax.swing.JLabel ExecutionjLabel1;
    private javax.swing.JLabel ExecutionjLabel2;
    private javax.swing.JButton ExitjButton;
    private javax.swing.JMenu FilejMenu;
    private javax.swing.JMenu HelpjMenu;
    private javax.swing.JRadioButton PIjRadioButton;
    private javax.swing.JRadioButtonMenuItem PIjRadioButtonMenuItem;
    private javax.swing.JButton PrintjButton;
    private javax.swing.JMenu appjMenu;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JMenuItem clearjMenuItem;
    private javax.swing.JLabel inputjLabel;
    private javax.swing.JPanel inputjPanel;
    private javax.swing.JTextField inputjTextField;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.ButtonGroup menuGroup;
    private javax.swing.JLabel methodjLabel1;
    private javax.swing.JLabel methodjLabel2;
    private javax.swing.JPanel optionjPanel;
    private javax.swing.JMenuItem printjMenuItem;
    private javax.swing.JMenuItem quitjMenuItem;
    private javax.swing.JPanel resultjPanel1;
    private javax.swing.JPanel resultjPanel2;
    private javax.swing.JLabel rsltjLabel1;
    private javax.swing.JLabel rsltjLabel2;
    private javax.swing.JLabel titleJLabel;
    private javax.swing.JLabel valErrorjLabel1;
    private javax.swing.JLabel valErrorjLabel2;
    private javax.swing.JLabel valExecutionjLabel1;
    private javax.swing.JLabel valExecutionjLabel2;
    // End of variables declaration//GEN-END:variables
}
